package com.gohome.gohomechat.model.entify;

import android.os.Parcel;
import android.os.Parcelable;

import com.gohome.gohomechat.utils.PinYinUtils;

import java.util.Comparator;

/**
 * Created by dllo on 16/3/11.
 */
public class Group implements Parcelable,Comparable<Group>{
    private String groupName;
    private String groupId;
    private String groupHead;
    private String pinyin;

    public Group() {
    }

    public Group(String groupName, String groupId) {
        this.groupName = groupName;
        this.groupId = groupId;
        pinyin = PinYinUtils.getPinYin(groupName).toUpperCase();
        if (!pinyin.substring(0, 1).matches("[A-Z]")) {
            pinyin = "#" + pinyin;
        }
    }

    public Group(String groupName, String groupId, String groupHead) {
        this.groupName = groupName;
        this.groupId = groupId;
        this.groupHead = groupHead;

        pinyin = PinYinUtils.getPinYin(groupName).toUpperCase();

        if (!pinyin.substring(0, 1).matches("[A-Z]")) {
            pinyin = "#" + pinyin;
        }
    }

    protected Group(Parcel in) {
        groupName = in.readString();
        groupId = in.readString();
        groupHead = in.readString();
        pinyin = in.readString();
    }

    public static final Creator<Group> CREATOR = new Creator<Group>() {
        @Override
        public Group createFromParcel(Parcel in) {
            return new Group(in);
        }

        @Override
        public Group[] newArray(int size) {
            return new Group[size];
        }
    };

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public String getGroupId() {
        return groupId;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    public String getGroupHead() {
        return groupHead;
    }

    public void setGroupHead(String groupHead) {
        this.groupHead = groupHead;
    }

    public String getPinyin() {
        return pinyin;
    }

    public void setPinyin(String pinyin) {
        this.pinyin = pinyin;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(groupName);
        dest.writeString(groupId);
        dest.writeString(groupHead);
        dest.writeString(pinyin);
    }

    @Override
    public int compareTo(Group another) {
        return this.pinyin.compareTo(another.getPinyin());
    }
}
